package com.sky.config;

import org.springframework.stereotype.Component;

@Component
public class UserContext {
    private static final ThreadLocal<Long> currentUserId = new ThreadLocal<>();

    // 设置当前用户ID（在登录拦截器或过滤器中调用）
    public static void setCurrentUserId(Long userId) {
        currentUserId.set(userId);
    }

    // 获取当前用户ID
    public static Long getCurrentUserId() {
        return currentUserId.get();
    }

    // 清除当前用户ID（在请求结束时调用）
    public static void clear() {
        currentUserId.remove();
    }
}